import 'package:flutter/material.dart';
import 'package:hi_flutter/app_page.dart';

/**
 * 用于拦截默认的手势事件和返回按钮事件
 *
 *  canPop: false 的时候回拦截掉  onPopInvoked这个方法会回调提醒 然后做拦截事件处理
 */
class PopScopeDemoPage extends StatelessWidget {
  const PopScopeDemoPage({super.key});

  @override
  Widget build(BuildContext context) {
    return PopScope(
        canPop: false,
        onPopInvoked: (bool didPop) async {
          if(didPop){
            return;
          }
          print(didPop);
        },
      child: AppPage(
        body: Center(
          child: ElevatedButton(
            onPressed: () {
              Navigator.of(context).pop();
            },
            child: const Text('返回'),
          ),
        ),
      ),
    );
  }
}
